In the New Project dialog box, on the left under Installed Templates, choose Visual C# and then Silverlight for Windows Phone. In the middle area, choose Windows Phone Application. Select a location for the project, and enter the project name: SilverlightHelloPhone.
As the project is created
you’ll see an image of a large-screen phone in portrait mode with a
screen area 480 x 800 pixels in size. This is the design
view. Although you can interactively pull controls from a toolbox to
design the application, I’m going to focus instead on showing you how to
write your own code and markup.
Several files have been created for this SilverlightHelloPhone project and are listed under the project name in the Solution Explorer over at the right. In the Properties folder are three files that you can usually ignore when you’re just creating little sample Silverlight programs for the phone. Only when you’re actually in the process of making a real application do these files become important.
However, you might want to open the WMAppManifest.xml file. In the App tag near the top, you’ll see the attribute:
Title="SilverlightHelloPhone"
That’s just the project name you selected. Insert some spaces to make it a little friendlier:
Title="Silverlight Hello Phone"
This is the name used by the
phone and the phone emulator to display the program in the list of
installed applications presented to the user. If you’re really
ambitious, you can also edit the ApplicationIcon.png and Background.png files that the phone uses to visually symbolize the program. The SplashScreenImage.jpg file is what the program displays as it’s initializing.
In the standard Visual Studio
toolbar under the program’s menu, you’ll see a drop-down list probably
displaying “Windows Phone 7 Emulator.” The other choice is “Windows Phone 7 Device.” This is how you deploy your program to either the emulator or an actual phone connected to your computer via USB.
Just to see that
everything’s working OK, select Windows Phone 7 Emulator and press F5
(or select Start Debugging from the Debug menu). Your program will
quickly build and in the status bar you’ll see the text “Connecting to
Windows Phone 7 Emulator…” The first time
you use the emulator during a session, it might take a little time to
start up. If you leave the emulator running between edit/build/run
cycles, Visual Studio doesn’t need to establish this connection again.
Soon the phone emulator
will appear on the desktop and you’ll see the opening screen, followed
soon by this little do-nothing Silverlight program as it is deployed and
run on the emulator. On the phone you’ll see pretty much the same image
you saw in the design view.
The phone emulator has a little floating
menu at the upper right that comes into view when you move the mouse to
that location. You can change orientation through this menu, or change
the emulator size. By default, the emulator is displayed at 50% actual
size, about the same size as the image on this page. When you display
the emulator at 100%, it becomes enormous, and you might wonder “How
will I ever fit a phone this big into my pocket?”
The difference involves pixel
density. Your computer screen probably has about 100 pixels per inch.
(By default, Windows assumes that screens are 96 DPI.) The screen on an
actual Windows
Phone 7 device is more than 2½ times that. When you display the emulator
at 100%, you’re seeing all the pixels of the phone’s screen, but at
about 250% their actual size.
You can terminate execution of this program and return to editing the program either though Visual Studio (using Shift-F5 or by selecting Stop Debugging from the Debug menu) or by clicking the Back button on the emulator.
Don’t exit the emulator itself by clicking the X at the top of the floating menu! Keeping the emulator running will make subsequent deployments go much faster.
While the emulator is
still running, it retains all programs deployed to it. If you click the
arrow at the upper-right of the Start screen, you’ll get a list that
will include this program identified by the text “Silverlight Hello
Phone” and you can run the program again. The program will disappear
from this list when you exit the emulator.
If you have a Windows Phone 7 device, you’ll need to register for the marketplace at the Windows Phone 7 portal, http://developer.windowsphone.com. After you’re approved, you’ll to connect the phone to your PC and run the Zune desktop software. You can unlock the phone for development by running the Windows
Phone Developer Registration program and entering your Windows Live ID.
You can then deploy programs to the phone from Visual Studio.